package com.huluobo.high3demo.startLive;

import androidx.lifecycle.MutableLiveData;

import com.huluobo.mvvm.baen.PushBeanResult;
import com.huluobo.mvvm.baen.StopPushBeanResult;
import com.huluobo.mvvm.model.BaseRepo;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by LC on 2023/9/27.
 */
public class StartLiveRepo extends BaseRepo {
    public void startPush(String address, String caption, MutableLiveData<PushBeanResult> success,
                          MutableLiveData<String> failed) {
        apiService.push(address, caption).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<PushBeanResult>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(PushBeanResult pushBeanResult) {
                        success.setValue(pushBeanResult);
                    }

                    @Override
                    public void onError(Throwable e) {
                        failed.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

    public void stopPush(MutableLiveData<StopPushBeanResult> success, MutableLiveData<String> failed) {
        apiService.stopPush().subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<StopPushBeanResult>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(StopPushBeanResult stopPushBeanResult) {
                        success.setValue(stopPushBeanResult);
                    }

                    @Override
                    public void onError(Throwable e) {
                        failed.setValue(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
